/********************************************************/
/*	Copyright (C) 2016 Gong Li Bin		 	*/
/*	Project:	GoLib-1.0.0			*/
/*	Author:		gong_libin			*/
/*	Date:		2016_01_01			*/
/*	File:		GoHttp.go			*/
/********************************************************/

package GoPro

import (
	"bufio"
	"strings"
	"net/http"
)

type GoHttpReq struct {
	req	*http.Request
}

func (r *GoHttpReq) GoHttpReqHost() string {
	return r.req.Host
}

func (r *GoHttpReq) GoHttpReqPath() string {
	return r.req.URL.Path
}

func (r *GoHttpReq) GoHttpReqProto() string {
	return r.req.Proto
}

func (r *GoHttpReq) GoHttpReqMethod() string {
	return r.req.Method
}

func (r *GoHttpReq) GoHttpReqAccept() string {
	return r.req.Header.Get("Accept")
}

func (r *GoHttpReq) GoHttpReqReferer() string {
	return r.req.Referer()
}

func (r *GoHttpReq) GoHttpReqUsrAgent() string {
	return r.req.UserAgent()
}

func (r *GoHttpReq) GoHttpReqConnection() string {
	return r.req.Header.Get("Connection")
}

func (r *GoHttpReq) GoHttpReqContentType() string {
	return r.req.Header.Get("Content-Type")
}

func (r *GoHttpReq) GoHttpReqContentLength() int64 {
	return r.req.ContentLength
}

func (r *GoHttpReq) GoHttpReqCacheControl() string {
	return r.req.Header.Get("Cache-Control")
}

func (r *GoHttpReq) GoHttpReqAcceptEncoding() string {
	return r.req.Header.Get("Accept-Encoding")
}

func (r *GoHttpReq) GoHttpReqAcceptLanguage() string {
	return r.req.Header.Get("Accept-Language")
}

func (r *GoHttpReq) GoHttpReqParse(b []byte) (err error) {
	r.req, err = http.ReadRequest(bufio.NewReader(strings.NewReader(string(b))))
	return err
}

func (r *GoHttpReq) GoHttpReqCookies() []string {
	ss := make([]string, 0)
	cc := r.req.Cookies()
	for _, v := range cc {
		ss = append(ss, v.Name + "=" + v.Value)
	}
	return ss
}
